//
//  KCellModelConfig.m
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 ZHBen. All rights reserved.
//
#import "KCellModelConfig.h"

@interface KCellModelConfig()

@property (strong,nonatomic) NSString * reuseIdentfier;

@property (strong,nonatomic) Class cellClass;

@end

@implementation KCellModelConfig

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        _rowHeight = UITableViewAutomaticDimension;
        _estimatedRowHeight = UITableViewAutomaticDimension;
    }
    return self;
}

+ (KCellModelConfig *)configWithModelClass:(Class)modelClass configBlock:(KCellConfigBlock)configBlock selectBlock:(KCellSelectBlock)selectBlock rowHeight:(CGFloat)rowHeight
{
    KCellModelConfig * config = [KCellModelConfig new];
    config.modelClass = modelClass;
    config.configBlock = configBlock;
    config.selectBlock = selectBlock;
    config.rowHeight = rowHeight;
    return config;
}

- (BOOL)isEqual:(id)object
{
    if (!_modelClass || ![object modelClass])
    {
        return [_reuseIdentfier isEqualToString:[object reuseIdentfier]];
    }
    return [_reuseIdentfier isEqualToString:[object reuseIdentfier]] && [NSStringFromClass(_modelClass) isEqualToString:NSStringFromClass([object modelClass])];
}

- (instancetype)copyWithZone:(NSZone *)zone
{
    KCellModelConfig * config = [[KCellModelConfig allocWithZone:zone] init];
    config.reuseIdentfier = _reuseIdentfier;
    config.modelClass = _modelClass;
    config.cellClass = _cellClass;
    config.configBlock = _configBlock;
    config.selectBlock = _selectBlock;
    config.rowHeight = _rowHeight;
    config.canDelete = _canDelete;
    config.canMove = _canMove;
    config.deleteConfirmBlock = _deleteConfirmBlock;
    config.actionList = _actionList;
    config.estimatedRowHeight = _estimatedRowHeight;
    return config;
}

- (CGFloat)estimatedRowHeight
{
    return _rowHeight != UITableViewAutomaticDimension ? _rowHeight : _estimatedRowHeight;
}

@end
